# -*- coding: utf-8 -*-
import json
import sys
import csv
import os  
from os.path import join, getsize 
list={}
def getdirsize(dir): 
	for root, dirs, files in os.walk(dir):
		for name in files:			
			if name.find('lineloss-m')==0:
				readACsv(join(root, name))
def readACsv(filePath):
	f=open(filePath,'rb')
	reader=csv.reader(f)
	i=0
	for line in reader:
		i+=1
		openTheJsonWithLine(line[0])
	f.close()
def openTheJsonWithLine(line):
	words=line.split('\t')
	list.setdefault(words[0],words[1])
if __name__ == '__main__':
	folder='F:/finaldesign/gitoschina/project d3/datatesting.csv'
	if len(sys.argv)==3:
		folder=sys.argv[1]
		filesize = getdirsize(folder)
	if len(sys.argv)==3:
		file=open(sys.argv[2],'w')
	else:		
		filesize = getdirsize(folder)
		file=open('data3.json','w')
	file.write(json.dumps(list,sort_keys=True))
	file.close() 
